package com.ruoyi.system.fallbackFactory.impl;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.db.domain.system.dto.SysJob;
import com.ruoyi.system.fallbackFactory.RemoteJobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 用户服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteJobFallbackFactory implements FallbackFactory<RemoteJobService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteJobFallbackFactory.class);

    @Override
    public RemoteJobService create(Throwable throwable)
    {
        log.error("定时任务服务调用失败:{}", throwable.getMessage());
        return new RemoteJobService()
        {
            @Override
            public R<AjaxResult> add(SysJob job, String source) {
                return R.fail("添加定时任务失败:" + throwable.getMessage());
            }

            @Override
            public R<AjaxResult> edit(SysJob job, String source) {
                return R.fail("修改定时任务失败:" + throwable.getMessage());
            }

            @Override
            public R<AjaxResult> remove(Long[] jobIds, String source) {
                return R.fail("删除定时任务失败:" + throwable.getMessage());
            }
        };
    }
}
